package com.sword.www.designPattern.prototype;

/**
 * 具体原型：原型模式实现类
 *
 * @author linmeng
 * @version 1.0
 * @date 2021年11月11日 22:39
 */
public class ConcretePrototype implements Prototype {

    private String type;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void show(){
        System.out.println("原型模式实现类");
    }
    @Override
    public Prototype clone() {
        Prototype prototype = null;
        try {
            prototype = (Prototype)super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return prototype;
    }
    /**
     * 判断克隆方法是否调用构造创建对象
     */
    public ConcretePrototype() {
        System.out.println("构造方法被调用");
    }

    public static void main(String[] args) {
        ConcretePrototype concretePrototype = new ConcretePrototype();
        ConcretePrototype clone = (ConcretePrototype)concretePrototype.clone();
        clone.show();
    }
}
